<?php

/**
 * Seller form.
 *
 * @package    ndirou_affaire
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class SellerForm extends BaseSellerForm
{
  public function configure()
  {
  	unset($this['created_at'], $this['updated_at'], $this['adses_list'], $this['address_id']);
  	$this->widgetSchema['gender']  = new sfWidgetFormChoice( array( 'choices'  => array('mr'=>'Mr.', 'mme' => 'Mme.', 'mlle' => 'Mlle'), 'multiple' => false, 'expanded' => true, ));

  	$this->widgetSchema['town_id'] = new sfWidgetFormDoctrineChoice(array( 
                'model'     => 'Town',    
                'order_by'  => array('num', 'asc'),    
                'multiple'  => false,    
                'add_empty' => false,
                'method'    => 'getFullTitle',
	));
		
        $this->widgetSchema['password'] = new sfWidgetFormInputPassword(array(),array());
        $this->widgetSchema['passwordConfirm'] = new sfWidgetFormInputPassword(array(),array());
        
        /* utiliser widgetText en edition */
        if( !$this->isNew() ){
            $this->widgetSchema['email'] = new sfWidgetFormText( array('value' => $this->getObject()->getEmail()) );
        }
        
        
  	$this->widgetSchema->setLabels( array(
  		'gender' => 'Civilité',
  		'firstname' => 'Prénom *',
  		'lastname' => 'Nom *',
  		'email' => 'E-Mail *',
  		'phone' => 'Tél.',
  		'mobile' => 'Mobile',
  		'password' => 'Mot de passe *',
                'passwordConfirm'   => 'Confirmer le mot de passe *',
  		'street' => 'Rue',
  		'zipcode' => 'Code postal',
  		'town_id' => 'Ville *',
  		'country' => 'Pays',
  		'newsletter' => 'Recevoir nos bonnes affaires ?',
        
  	));
  	
  	
  	$this->validatorSchema['firstname'] 	= new sfValidatorString(array('required' => true));
        $this->validatorSchema['lastname']  	= new sfValidatorString(array('required' => true));
        $this->validatorSchema['town_id']  	= new sfValidatorString(array('required' => true));
        $this->validatorSchema['email']     = new sfValidatorEmail(array('required' => $this->isNew())); 
        $this->validatorSchema['zipcode']   	= new sfValidatorRegex(array('pattern' => '/^[0-9]{5}$/', 'required' => false));
        $this->validatorSchema['mobile']   	= new sfValidatorRegex(array('pattern' => '/^[0-9]{10}$/', 'required' => false));
        $this->validatorSchema['password'] 	= new sfValidatorString(array('required' => true));
        $this->validatorSchema['passwordConfirm'] 	= new sfValidatorString(array('required' => true));
        
        $this->validatorSchema['password']->setMessage('required', 'Veuillez remplir le champ Mot de passe');
        $this->validatorSchema['passwordConfirm']->setMessage('required', 'Veuillez confirmer le Mot de passe');
        $this->validatorSchema['zipcode']->setMessage('required', 'Veuillez remplir le champ Code Postal');
        $this->validatorSchema['zipcode']->setMessage('invalid', 'Le code postal doit contenir 5 chiffres');
        $this->validatorSchema['mobile']->setMessage('required', 'Veuillez remplir le champ Téléphone');
        $this->validatorSchema['mobile']->setMessage('invalid', 'Le numéro de téléphone doit contenir 10 chiffres');
        $this->validatorSchema['town_id']->setMessage('required', 'Veuillez remplir le champ Ville');

        $this->validatorSchema['firstname']->setMessage('required', 'Veuillez remplir le champ Prénom');
	$this->validatorSchema['lastname']->setMessage('required', 'Veuillez remplir le champ Nom');
	$this->validatorSchema['email']->setMessage('required', 'Veuillez remplir le champ E-Mail');
	$this->validatorSchema['email']->setMessage('invalid', 'Le champ "E-Mail" est invalide');
	    
        
        $this->validatorSchema->setPostValidator(
              new sfValidatorSchemaCompare(
                'password',
                sfValidatorSchemaCompare::EQUAL,
                'passwordConfirm',
                array(),
                array('invalid' => 'Veuillez vérifier les champs mot de passe')
              )
        );
        
	if( $this->isNew() ){
            $this->mergePostValidator(new bay3ValidatorSeller(array('email_field' => 'email'), array('invalid' => 'Cet email est déjà utilisé par un autre annonceur')));
	}
        
	
  	$this->widgetSchema->setNameFormat('subscription[%s]');
	$this->widgetSchema->setFormFormatterName('div');
	$this->widgetSchema->getFormFormatter()->setTranslationCatalogue('messages');
  }
}
